#ifndef DATABASE_H
#define DATABASE_H

#include <QtGui>
#include <QtSql>

#include "ConnectionDialog.h"
#include "ScheduleManager.h"

#define PROGRAM "program"
#define FACULTY "faculty"
#define ROOM "room"
#define COURSE "course"
#define SCHEDULE "schedule"

class Database : public QObject
{
	Q_OBJECT

public:
	enum DatabaseType
	{
		DT_DEFAULT,
		DT_PROGRAM,
		DT_FACULTY,
		DT_ROOM,
		DT_COURSE,
		DT_SCHEDULE
	};


public:
	//! This singleton must be initialized before use.
	static void initialize( QObject* parent );

	//! Returns the singleton instance.
	static Database* instance();

private:
	//! Constructor
	/*!
		@param parent See QObject.
	*/
	Database( QObject* parent );
	//! Destructor
	~Database();
	//! No Copy Constructor.
	Database( Database const& );
	//! No Assignment Operator.
	void operator = ( Database const& ); 

public:
	void query( const QString& query );

	inline QSqlTableModel* programModel(){ return mProgramModel; }
	inline QSqlTableModel* facultyModel(){ return mFacultyModel; }
	inline QSqlTableModel* roomModel(){ return mRoomModel; }
	inline QSqlTableModel* courseModel(){ return mCourseModel; }
	inline QSqlTableModel* scheduleModel(){ return mScheduleModel; }

public slots:
	void submit();
	void revert();

private:
	QSqlDatabase mSQLDatabase;

	QSqlTableModel* mProgramModel;
	QSqlTableModel* mFacultyModel;
	QSqlTableModel* mRoomModel;
	QSqlTableModel* mCourseModel;
	QSqlTableModel* mScheduleModel;
};

#endif // DATABASE_H